function [start_index, end_index] = CalculateStationaryWindowSize (bit_position, window_size, step_size, serial)
start_index = bit_position - round (window_size / 2);
end_index = bit_position + round (window_size / 2);
while start_index < end_index
  if kpsstest (serial (start_index: end_index), 'alpha', 0.01, 'trend',false) %fail test
    start_index = start_index + step_size;
    end_index = end_index - step_size;
    continue;
  else
    break;
  end
end
